<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>项目进度管理看板</title>
    <style>
        :root {
            --primary-color: #3498db;
            --success-color: #2ecc71;
            --warning-color: #f39c12;
            --danger-color: #e74c3c;
            --light-color: #f5f5f5;
            --dark-color: #333;
            --border-radius: 8px;
            --box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
        }
        
        body {
            background-color: #f5f7fa;
            color: var(--dark-color);
            padding: 20px;
            line-height: 1.6;
        }
        
        .container {
            max-width: 1400px;
            margin: 0 auto;
        }
        
        header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 25px;
            padding-bottom: 15px;
            border-bottom: 1px solid #e1e4e8;
        }
        
        h1 {
            color: #2c3e50;
            font-size: 28px;
            font-weight: 600;
        }
        
        .header-actions {
            display: flex;
            gap: 10px;
        }
        
        button {
            padding: 10px 20px;
            background-color: var(--primary-color);
            color: white;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.3s;
            font-weight: 500;
        }
        
        button:hover {
            background-color: #2980b9;
        }
        
        .import-btn {
            background-color: var(--warning-color);
        }
        
        .import-btn:hover {
            background-color: #e67e22;
        }
        
        .export-btn {
            background-color: var(--success-color);
        }
        
        .export-btn:hover {
            background-color: #27ae60;
        }
        
        .file-input-container {
            position: relative;
            display: inline-block;
        }
        
        .file-input {
            position: absolute;
            left: 0;
            top: 0;
            opacity: 0;
            width: 100%;
            height: 100%;
            cursor: pointer;
        }
        
        /* 统计面板布局 */
        .stats-container {
            display: flex;
            gap: 20px;
            margin-bottom: 30px;
        }
        
        .status-stats, .category-stats {
            flex: 1;
            background: white;
            border-radius: var(--border-radius);
            padding: 20px;
            box-shadow: var(--box-shadow);
        }
        
        .stats-grid {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 20px;
        }
        
        .category-grid {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 15px;
        }
        
        .stat-item {
            text-align: center;
            padding: 15px;
            border-radius: var(--border-radius);
            background: #f8f9fa;
        }
        
        .stat-value {
            font-size: 28px;
            font-weight: 700;
            margin-bottom: 5px;
        }
        
        .stat-input {
            width: 100%;
            font-size: 28px;
            font-weight: 700;
            text-align: center;
            border: none;
            background: transparent;
            border-bottom: 2px solid #3498db;
            padding: 5px;
            margin-bottom: 5px;
        }
        
        .stat-label {
            font-size: 14px;
            color: #7f8c8d;
        }
        
        .category-item {
            text-align: center;
            padding: 12px;
            border-radius: var(--border-radius);
            background: #f8f9fa;
        }
        
        .category-name {
            font-size: 14px;
            color: #7f8c8d;
            margin-bottom: 5px;
        }
        
        .category-count {
            font-size: 20px;
            font-weight: 700;
        }
        
        /* 表格样式 */
        .projects-table-container {
            background: white;
            border-radius: var(--border-radius);
            box-shadow: var(--box-shadow);
            overflow: hidden;
            margin-bottom: 30px;
        }
        
        .table-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 20px;
            border-bottom: 1px solid #e1e4e8;
        }
        
        .table-controls {
            display: flex;
            gap: 15px;
            align-items: center;
        }
        
        .search-box {
            padding: 10px 15px;
            border: 1px solid #ddd;
            border-radius: 6px;
            width: 250px;
        }
        
        .filter-btn {
            background-color: #ecf0f1;
            color: #2c3e50;
        }
        
        .filter-btn.active {
            background-color: var(--primary-color);
            color: white;
        }
        
        table {
            width: 100%;
            border-collapse: collapse;
        }
        
        th, td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid #e1e4e8;
        }
        
        th {
            background-color: #f8f9fa;
            font-weight: 600;
            color: #2c3e50;
            position: sticky;
            top: 0;
            z-index: 100;
        }
        
        tr:hover {
            background-color: #f5f7fa;
        }
        
        .phase-cell {
            white-space: nowrap;
            font-size: 13px;
            padding: 0;
            position: relative;
        }
        
        .phase-on-time {
            color: var(--success-color);
            font-weight: 500;
        }
        
        .phase-overdue {
            color: var(--danger-color);
            font-weight: 600;
        }
        
        .action-btn {
            background: none;
            border: none;
            color: var(--primary-color);
            cursor: pointer;
            padding: 5px 10px;
            border-radius: 4px;
            transition: background 0.3s;
        }
        
        .action-btn:hover {
            background: #f0f7ff;
        }
        
        /* 阶段色块样式 - 保持分离但视觉上连接 */
        .phase-segment {
            height: 24px;
            width: 100%;
            position: relative;
            cursor: pointer;
            transition: opacity 0.3s;
            border-radius: 0;
        }
        
        .phase-segment:hover {
            opacity: 0.8;
        }
        
        .phase-segment.completed {
            background-color: var(--success-color);
        }
        
        .phase-segment.warning {
            background-color: var(--warning-color);
        }
        
        .phase-segment.overdue {
            background-color: var(--danger-color);
        }
        
        .phase-segment.overdue-completed {
            background-color: var(--danger-color);
            background-image: repeating-linear-gradient(
                45deg,
                transparent,
                transparent 2px,
                rgba(255,255,255,0.3) 2px,
                rgba(255,255,255,0.3) 4px
            );
        }
        
        .phase-segment.future {
            background-color: transparent;
            border: 1px dashed #ddd;
        }
        
        .phase-segment:hover::after {
            content: attr(data-phase) ": " attr(data-planned) " (计划)" "\A实际: " attr(data-actual);
            white-space: pre;
            position: absolute;
            bottom: 100%;
            left: 50%;
            transform: translateX(-50%);
            background: #333;
            color: white;
            padding: 5px 10px;
            border-radius: 4px;
            font-size: 12px;
            z-index: 10;
            max-width: 200px;
            text-align: center;
        }
        
        /* 使相邻色块视觉上连接 */
        .phase-segment:first-child {
            border-top-left-radius: 4px;
            border-bottom-left-radius: 4px;
        }
        
        .phase-segment:last-child {
            border-top-right-radius: 4px;
            border-bottom-right-radius: 4px;
        }
        
        /* 颜色图例 */
        .color-legend {
            display: flex;
            gap: 15px;
            margin-bottom: 10px;
        }
        
        .legend-item {
            display: flex;
            align-items: center;
            gap: 5px;
            font-size: 12px;
        }
        
        .legend-color {
            width: 15px;
            height: 15px;
            border-radius: 3px;
        }
        
        /* 状态选择下拉框样式 - 美化版本 */
        .status-select {
            padding: 10px 15px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 14px;
            background-color: white;
            cursor: pointer;
            min-width: 140px;
            transition: all 0.3s ease;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 9L2 5h8z'/%3E%3C/svg%3E");
            background-repeat: no-repeat;
            background-position: right 12px center;
            padding-right: 35px;
            appearance: none;
            -webkit-appearance: none;
            -moz-appearance: none;
        }
        
        .status-select:hover {
            border-color: #3498db;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
        }
        
        .status-select:focus {
            outline: none;
            border-color: #3498db;
            box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
        }
        
        .status-select option {
            padding: 8px 12px;
        }
        
        /* 品类筛选下拉框样式 */
        .category-select {
            padding: 10px 15px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 14px;
            background-color: white;
            cursor: pointer;
            min-width: 140px;
            transition: all 0.3s ease;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 9L2 5h8z'/%3E%3C/svg%3E");
            background-repeat: no-repeat;
            background-position: right 12px center;
            padding-right: 35px;
            appearance: none;
            -webkit-appearance: none;
            -moz-appearance: none;
        }
        
        .category-select:hover {
            border-color: #3498db;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
        }
        
        .category-select:focus {
            outline: none;
            border-color: #3498db;
            box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
        }
        
        .category-select option {
            padding: 8px 12px;
        }
        
        /* 不同状态的颜色标识 */
        .status-research {
            color: #3498db;
        }
        
        .status-completed {
            color: #2ecc71;
        }
        
        .status-paused {
            color: #f39c12;
        }
        
        .status-terminated {
            color: #e74c3c;
        }
        
        /* 模态框样式 */
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            justify-content: center;
            align-items: center;
            z-index: 1000;
        }
        
        .modal-content {
            background-color: white;
            padding: 30px;
            border-radius: var(--border-radius);
            width: 90%;
            max-width: 1000px;
            max-height: 90vh;
            overflow-y: auto;
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 600;
            color: #2c3e50;
        }
        
        input, select, textarea {
            width: 100%;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 15px;
        }
        
        textarea {
            height: 100px;
            resize: vertical;
        }
        
        .form-row {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 15px;
        }
        
        .phase-inputs {
            display: grid;
            grid-template-columns: 1fr 1fr 1fr;
            gap: 10px;
            margin-bottom: 10px;
        }
        
        .form-actions {
            display: flex;
            justify-content: flex-end;
            gap: 15px;
            margin-top: 25px;
        }
        
        .complete-btn {
            background-color: var(--success-color);
        }
        
        .complete-btn:hover {
            background-color: #27ae60;
        }
        
        @media (max-width: 1200px) {
            .stats-container {
                flex-direction: column;
            }
            
            .category-grid {
                grid-template-columns: repeat(2, 1fr);
            }
        }
        
        @media (max-width: 768px) {
            .form-row, .phase-inputs {
                grid-template-columns: 1fr;
            }
            
            .table-controls {
                flex-direction: column;
                align-items: stretch;
            }
            
            .search-box {
                width: 100%;
            }
            
            table {
                display: block;
                overflow-x: auto;
            }
            
            .status-select, .category-select {
                min-width: 120px;
                font-size: 13px;
                padding: 8px 10px;
                padding-right: 30px;
            }
            
            .header-actions {
                flex-direction: column;
                width: 100%;
            }
            
            .header-actions button {
                width: 100%;
                margin-bottom: 10px;
            }
        }
    </style>
    <!-- 引入SheetJS库用于Excel导入导出 -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
</head>
<body>
    <div class="container">
        <header>
            <h1>项目进度管理看板</h1>
            <div class="header-actions">
                <button id="addProjectBtn">+ 添加新项目</button>
                <div class="file-input-container">
                    <button id="importExcelBtn" class="import-btn">导入Excel</button>
                    <input type="file" id="excelFile" class="file-input" accept=".xlsx, .xls">
                </div>
                <button id="exportExcelBtn" class="export-btn">导出Excel</button>
            </div>
        </header>
        
        <!-- 统计面板 -->
        <div class="stats-container">
            <div class="status-stats">
                <h3 style="margin-bottom: 15px;">项目状态统计</h3>
                <div class="stats-grid">
                    <div class="stat-item">
                        <div class="stat-value" id="researchCount">0</div>
                        <div class="stat-label">在研项目数量</div>
                    </div>
                    <div class="stat-item">
                        <input type="number" class="stat-input" id="evaluationCount" value="0" min="0">
                        <div class="stat-label">评估中的项目数量</div>
                    </div>
                    <div class="stat-item">
                        <div class="stat-value" id="dueThisMonthCount">0</div>
                        <div class="stat-label">本月需结项项目数量</div>
                    </div>
                    <div class="stat-item">
                        <div class="stat-value" id="pendingThisMonthCount">0</div>
                        <div class="stat-label">本月待结项项目数量</div>
                    </div>
                </div>
            </div>
            
            <div class="category-stats">
                <h3 style="margin-bottom: 15px;">项目品类统计</h3>
                <div class="category-grid" id="categoryStats">
                    <!-- 品类统计将通过JavaScript动态生成 -->
                </div>
            </div>
        </div>
        
        <!-- 项目表格 -->
        <div class="projects-table-container">
            <div class="table-header">
                <h3>项目明细</h3>
                <div class="table-controls">
                    <div class="filter-buttons">
                        <button class="filter-btn active" data-filter="all">全部项目</button>
                        <button class="filter-btn" data-filter="research">在研项目</button>
                        <button class="filter-btn" data-filter="paused">暂停项目</button>
                        <button class="filter-btn" data-filter="terminated">终止项目</button>
                        <button class="filter-btn" data-filter="due">本月需结项</button>
                        <button class="filter-btn" data-filter="completed">已结项</button>
                    </div>
                    <div>
                        <div class="color-legend">
                            <div class="legend-item">
                                <div class="legend-color" style="background-color: var(--success-color);"></div>
                                <span>按时完成</span>
                            </div>
                            <div class="legend-item">
                                <div class="legend-color" style="background-color: var(--warning-color);"></div>
                                <span>即将到期(3天内)</span>
                            </div>
                            <div class="legend-item">
                                <div class="legend-color" style="background-color: var(--danger-color);"></div>
                                <span>超期未完成</span>
                            </div>
                            <div class="legend-item">
                                <div class="legend-color" style="background-color: var(--danger-color); background-image: repeating-linear-gradient(45deg, transparent, transparent 2px, rgba(255,255,255,0.3) 2px, rgba(255,255,255,0.3) 4px);"></div>
                                <span>超期完成</span>
                            </div>
                            <div class="legend-item">
                                <div class="legend-color" style="border: 1px dashed #ddd; background-color: transparent;"></div>
                                <span>未开始</span>
                            </div>
                        </div>
                        <div style="display: flex; gap: 10px; align-items: center;">
                            <select class="category-select" id="categoryFilter">
                                <option value="all">全部品类</option>
                                <!-- 品类选项将通过JavaScript动态生成 -->
                            </select>
                            <input type="text" class="search-box" id="searchInput" placeholder="搜索产品型号...">
                        </div>
                    </div>
                </div>
            </div>
            
            <div style="overflow-x: auto; max-height: 70vh;">
                <table id="projectsTable">
                    <thead>
                        <tr>
                            <th>产品品类</th>
                            <th>产品型号</th>
                            <th>项目周期</th>
                            <th>方案评估</th>
                            <th>需求确定</th>
                            <th>初样评审</th>
                            <th>样机评审</th>
                            <th>立项</th>
                            <th>外观样机</th>
                            <th>样机测试</th>
                            <th>产品认证</th>
                            <th>试产准备</th>
                            <th>试产</th>
                            <th>结项</th>
                            <th>入库时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <!-- 项目数据将通过JavaScript动态生成 -->
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    
    <!-- 添加/编辑项目模态框 -->
    <div class="modal" id="projectModal">
        <div class="modal-content">
            <h2 id="modalTitle">添加新项目</h2>
            <form id="projectForm">
                <input type="hidden" id="projectId">
                
                <div class="form-row">
                    <div class="form-group">
                        <label for="productCategory">产品品类</label>
                        <input type="text" id="productCategory" required>
                    </div>
                    <div class="form-group">
                        <label for="productModel">产品型号</label>
                        <input type="text" id="productModel" required>
                    </div>
                </div>
                
                <div class="form-row">
                    <div class="form-group">
                        <label for="projectPeriod">项目周期</label>
                        <div style="display: flex; gap: 10px;">
                            <input type="date" id="startDate" required>
                            <span style="line-height: 44px;">至</span>
                            <input type="date" id="endDate" required>
                        </div>
                    </div>
                </div>
                
                <div class="form-group">
                    <label>项目阶段时间表</label>
                    
                    <div class="phase-inputs">
                        <div>阶段名称</div>
                        <div>计划完成日期</div>
                        <div>实际完成日期</div>
                    </div>
                    
                    <div class="phase-inputs">
                        <div>方案评估</div>
                        <input type="date" id="phase1-planned" class="phase-date-input">
                        <input type="date" id="phase1-actual" class="phase-date-input">
                    </div>
                    
                    <div class="phase-inputs">
                        <div>需求确定</div>
                        <input type="date" id="phase2-planned" class="phase-date-input">
                        <input type="date" id="phase2-actual" class="phase-date-input">
                    </div>
                    
                    <div class="phase-inputs">
                        <div>初样评审</div>
                        <input type="date" id="phase3-planned" class="phase-date-input">
                        <input type="date" id="phase3-actual" class="phase-date-input">
                    </div>
                    
                    <div class="phase-inputs">
                        <div>样机评审</div>
                        <input type="date" id="phase4-planned" class="phase-date-input">
                        <input type="date" id="phase4-actual" class="phase-date-input">
                    </div>
                    
                    <div class="phase-inputs">
                        <div>立项</div>
                        <input type="date" id="phase5-planned" class="phase-date-input">
                        <input type="date" id="phase5-actual" class="phase-date-input">
                    </div>
                    
                    <div class="phase-inputs">
                        <div>外观样机</div>
                        <input type="date" id="phase6-planned" class="phase-date-input">
                        <input type="date" id="phase6-actual" class="phase-date-input">
                    </div>
                    
                    <div class="phase-inputs">
                        <div>样机测试</div>
                        <input type="date" id="phase7-planned" class="phase-date-input">
                        <input type="date" id="phase7-actual" class="phase-date-input">
                    </div>
                    
                    <div class="phase-inputs">
                        <div>产品认证</div>
                        <input type="date" id="phase8-planned" class="phase-date-input">
                        <input type="date" id="phase8-actual" class="phase-date-input">
                    </div>
                    
                    <div class="phase-inputs">
                        <div>试产准备</div>
                        <input type="date" id="phase9-planned" class="phase-date-input">
                        <input type="date" id="phase9-actual" class="phase-date-input">
                    </div>
                    
                    <div class="phase-inputs">
                        <div>试产</div>
                        <input type="date" id="phase10-planned" class="phase-date-input">
                        <input type="date" id="phase10-actual" class="phase-date-input">
                    </div>
                    
                    <div class="phase-inputs">
                        <div>结项</div>
                        <input type="date" id="phase11-planned" class="phase-date-input">
                        <input type="date" id="phase11-actual" class="phase-date-input">
                    </div>
                    
                    <div class="phase-inputs">
                        <div>入库时间</div>
                        <input type="date" id="phase12-planned" class="phase-date-input">
                        <input type="date" id="phase12-actual" class="phase-date-input">
                    </div>
                </div>
                
                <div class="form-actions">
                    <button type="button" id="cancelBtn">取消</button>
                    <button type="submit" id="saveBtn">保存项目</button>
                </div>
            </form>
        </div>
    </div>

    <script>
        // 示例项目数据
        let projects = [
    {
        "id": 1,
        "category": "烟机",
        "model": "JQ9001",
        "startDate": "2023-10-01",
        "endDate": "2024-05-01",
        "phases": {
            "方案评估": {
                "planned": "2023-10-01",
                "actual": "2023-10-01"
            },
            "需求确定": {
                "planned": "2023-10-15",
                "actual": "2023-10-20"
            },
            "初样评审": {
                "planned": "2023-11-10",
                "actual": "2023-11-10"
            },
            "样机评审": {
                "planned": "2023-12-05",
                "actual": "2023-12-10"
            },
            "立项": {
                "planned": "2023-12-20",
                "actual": "2023-12-20"
            },
            "外观样机": {
                "planned": "2024-01-15",
                "actual": ""
            },
            "样机测试": {
                "planned": "2024-02-10",
                "actual": ""
            },
            "产品认证": {
                "planned": "2024-03-05",
                "actual": ""
            },
            "试产准备": {
                "planned": "2024-03-25",
                "actual": ""
            },
            "试产": {
                "planned": "2024-04-15",
                "actual": ""
            },
            "结项": {
                "planned": "2024-05-01",
                "actual": ""
            },
            "入库时间": {
                "planned": "",
                "actual": ""
            }
        },
        "status": "research"
    },
    {
        "id": 2,
        "category": "电热",
        "model": "DS5002",
        "startDate": "2023-09-15",
        "endDate": "2024-04-15",
        "phases": {
            "方案评估": {
                "planned": "2023-09-15",
                "actual": "2023-09-15"
            },
            "需求确定": {
                "planned": "2023-10-05",
                "actual": "2023-10-05"
            },
            "初样评审": {
                "planned": "2023-10-30",
                "actual": "2023-10-30"
            },
            "样机评审": {
                "planned": "2023-11-25",
                "actual": "2023-11-25"
            },
            "立项": {
                "planned": "2023-12-10",
                "actual": "2023-12-10"
            },
            "外观样机": {
                "planned": "2024-01-05",
                "actual": "2024-01-05"
            },
            "样机测试": {
                "planned": "2024-01-30",
                "actual": "2024-01-30"
            },
            "产品认证": {
                "planned": "2024-02-20",
                "actual": "2024-02-20"
            },
            "试产准备": {
                "planned": "2024-03-10",
                "actual": "2024-03-10"
            },
            "试产": {
                "planned": "2024-03-30",
                "actual": "2024-03-30"
            },
            "结项": {
                "planned": "2024-04-15",
                "actual": "2024-04-15"
            },
            "入库时间": {
                "planned": "",
                "actual": ""
            }
        },
        "status": "completed"
    },
    {
        "id": 3,
        "category": "取暖桌",
        "model": "测试1",
        "startDate": "2025-09-10",
        "endDate": "2025-10-31",
        "phases": {
            "方案评估": {
                "planned": "2025-09-10",
                "actual": ""
            },
            "需求确定": {
                "planned": "2025-09-15",
                "actual": ""
            },
            "初样评审": {
                "planned": "2025-09-17",
                "actual": ""
            },
            "样机评审": {
                "planned": "2025-09-22",
                "actual": ""
            },
            "立项": {
                "planned": "2025-09-25",
                "actual": ""
            },
            "外观样机": {
                "planned": "2025-09-30",
                "actual": ""
            },
            "样机测试": {
                "planned": "2025-10-10",
                "actual": ""
            },
            "产品认证": {
                "planned": "2025-10-20",
                "actual": ""
            },
            "试产准备": {
                "planned": "2025-10-20",
                "actual": ""
            },
            "试产": {
                "planned": "2025-10-22",
                "actual": ""
            },
            "结项": {
                "planned": "2025-11-30",
                "actual": ""
            },
            "入库时间": {
                "planned": "",
                "actual": ""
            }
        },
        "status": "research"
    },
    {
        "id": 1762012408583,
        "category": "取暖桌",
        "model": "测试2",
        "startDate": "2025-09-10",
        "endDate": "2025-10-31",
        "phases": {
            "方案评估": {
                "planned": "2025-09-10",
                "actual": ""
            },
            "需求确定": {
                "planned": "2025-09-15",
                "actual": ""
            },
            "初样评审": {
                "planned": "2025-09-17",
                "actual": ""
            },
            "样机评审": {
                "planned": "2025-09-22",
                "actual": ""
            },
            "立项": {
                "planned": "2025-09-25",
                "actual": ""
            },
            "外观样机": {
                "planned": "2025-09-30",
                "actual": ""
            },
            "样机测试": {
                "planned": "2025-10-10",
                "actual": ""
            },
            "产品认证": {
                "planned": "2025-10-20",
                "actual": ""
            },
            "试产准备": {
                "planned": "2025-10-20",
                "actual": ""
            },
            "试产": {
                "planned": "2025-10-22",
                "actual": ""
            },
            "结项": {
                "planned": "2025-11-02",
                "actual": ""
            },
            "入库时间": {
                "planned": "",
                "actual": ""
            }
        },
        "status": "research"
    },
    {
        "id": 1762012408584,
        "category": "灶具",
        "model": "测试",
        "startDate": "2025-09-10",
        "endDate": "2025-10-31",
        "phases": {
            "方案评估": {
                "planned": "2025-09-10",
                "actual": ""
            },
            "需求确定": {
                "planned": "2025-09-15",
                "actual": ""
            },
            "初样评审": {
                "planned": "2025-09-17",
                "actual": ""
            },
            "样机评审": {
                "planned": "2025-09-22",
                "actual": ""
            },
            "立项": {
                "planned": "2025-09-25",
                "actual": ""
            },
            "外观样机": {
                "planned": "2025-09-30",
                "actual": ""
            },
            "样机测试": {
                "planned": "2025-10-10",
                "actual": ""
            },
            "产品认证": {
                "planned": "2025-10-20",
                "actual": ""
            },
            "试产准备": {
                "planned": "2025-10-20",
                "actual": ""
            },
            "试产": {
                "planned": "2025-10-22",
                "actual": ""
            },
            "结项": {
                "planned": "2025-11-10",
                "actual": ""
            },
            "入库时间": {
                "planned": "",
                "actual": ""
            }
        },
        "status": "research"
    },
    {
        "id": 1762012408586,
        "category": "净水",
        "model": "测试",
        "startDate": "2025-09-10",
        "endDate": "2025-10-31",
        "phases": {
            "方案评估": {
                "planned": "2025-09-10",
                "actual": ""
            },
            "需求确定": {
                "planned": "2025-09-15",
                "actual": ""
            },
            "初样评审": {
                "planned": "2025-09-17",
                "actual": ""
            },
            "样机评审": {
                "planned": "2025-09-22",
                "actual": ""
            },
            "立项": {
                "planned": "2025-09-25",
                "actual": ""
            },
            "外观样机": {
                "planned": "2025-09-30",
                "actual": ""
            },
            "样机测试": {
                "planned": "2025-10-10",
                "actual": ""
            },
            "产品认证": {
                "planned": "2025-10-20",
                "actual": ""
            },
            "试产准备": {
                "planned": "2025-10-20",
                "actual": ""
            },
            "试产": {
                "planned": "2025-10-22",
                "actual": ""
            },
            "结项": {
                "planned": "2025-10-31",
                "actual": ""
            },
            "入库时间": {
                "planned": "",
                "actual": ""
            }
        },
        "status": "research"
    },
    {
        "id": 1762012408587,
        "category": "燃热",
        "model": "测试",
        "startDate": "2025-09-10",
        "endDate": "2025-10-31",
        "phases": {
            "方案评估": {
                "planned": "2025-09-10",
                "actual": ""
            },
            "需求确定": {
                "planned": "2025-09-15",
                "actual": ""
            },
            "初样评审": {
                "planned": "2025-09-17",
                "actual": ""
            },
            "样机评审": {
                "planned": "2025-09-22",
                "actual": ""
            },
            "立项": {
                "planned": "2025-09-25",
                "actual": ""
            },
            "外观样机": {
                "planned": "2025-09-30",
                "actual": ""
            },
            "样机测试": {
                "planned": "2025-10-10",
                "actual": ""
            },
            "产品认证": {
                "planned": "2025-10-20",
                "actual": ""
            },
            "试产准备": {
                "planned": "2025-10-20",
                "actual": ""
            },
            "试产": {
                "planned": "2025-10-22",
                "actual": ""
            },
            "结项": {
                "planned": "2025-10-31",
                "actual": ""
            },
            "入库时间": {
                "planned": "",
                "actual": ""
            }
        },
        "status": "research"
    }
];

        // 基础品类列表（烟机、电热、燃热、灶具、净水、壁挂炉）
        const baseCategories = ["烟机", "电热", "燃热", "灶具", "净水", "壁挂炉"];
        // 显示品类列表（基础品类 + 小家电）
        const displayCategories = [...baseCategories, "小家电"];

        // 阶段列表（排除入库时间）
        const phases = [
            "方案评估", "需求确定", "初样评审", "样机评审", "立项", 
            "外观样机", "样机测试", "产品认证", "试产准备", "试产", "结项"
        ];

        // DOM元素
        const projectsTable = document.getElementById('projectsTable').getElementsByTagName('tbody')[0];
        const projectModal = document.getElementById('projectModal');
        const projectForm = document.getElementById('projectForm');
        const modalTitle = document.getElementById('modalTitle');
        const addProjectBtn = document.getElementById('addProjectBtn');
        const importExcelBtn = document.getElementById('importExcelBtn');
        const exportExcelBtn = document.getElementById('exportExcelBtn');
        const excelFile = document.getElementById('excelFile');
        const cancelBtn = document.getElementById('cancelBtn');
        const filterBtns = document.querySelectorAll('.filter-btn');
        const searchInput = document.getElementById('searchInput');
        const evaluationCountInput = document.getElementById('evaluationCount');
        const categoryFilter = document.getElementById('categoryFilter');
        
        // 统计元素
        const researchCountEl = document.getElementById('researchCount');
        const dueThisMonthCountEl = document.getElementById('dueThisMonthCount');
        const pendingThisMonthCountEl = document.getElementById('pendingThisMonthCount');
        const categoryStatsEl = document.getElementById('categoryStats');

        // 当前过滤条件和搜索词
        let currentFilter = 'all';
        let searchTerm = '';
        let currentCategory = 'all';
        let editingProjectId = null;

        // 初始化看板
        function initKanban() {
            renderProjectsTable();
            updateStats();
            setupEventListeners();
            populateCategoryFilter();
            
            // 从本地存储加载手动设置的评估项目数量
            const savedEvaluationCount = localStorage.getItem('evaluationCount');
            if (savedEvaluationCount) {
                evaluationCountInput.value = savedEvaluationCount;
            }
        }

        // 渲染项目表格
        function renderProjectsTable() {
            projectsTable.innerHTML = '';
            
            const filteredProjects = projects.filter(project => {
                // 应用状态过滤器
                if (currentFilter !== 'all') {
                    if (currentFilter === 'due') {
                        // 本月需结项项目 - 修正为包括所有本月计划结项的项目，排除暂停和终止状态
                        const currentMonth = new Date().getMonth();
                        const currentYear = new Date().getFullYear();
                        const completionDate = new Date(project.phases['结项'].planned);
                        if (completionDate.getMonth() !== currentMonth || 
                            completionDate.getFullYear() !== currentYear ||
                            project.status === 'paused' || project.status === 'terminated') {
                            return false;
                        }
                    } else if (project.status !== currentFilter) {
                        return false;
                    }
                }
                
                // 应用品类筛选
                if (currentCategory !== 'all' && project.category !== currentCategory) {
                    return false;
                }
                
                // 应用搜索
                if (searchTerm && 
                    !project.model.toLowerCase().includes(searchTerm.toLowerCase())) {
                    return false;
                }
                
                return true;
            });
            
            if (filteredProjects.length === 0) {
                const row = projectsTable.insertRow();
                const cell = row.insertCell(0);
                cell.colSpan = 16;
                cell.textContent = '没有找到匹配的项目';
                cell.style.textAlign = 'center';
                cell.style.padding = '40px';
                cell.style.color = '#7f8c8d';
                return;
            }
            
            filteredProjects.forEach(project => {
                const row = projectsTable.insertRow();
                
                // 项目基本信息
                row.insertCell(0).textContent = project.category;
                row.insertCell(1).textContent = project.model;
                
                // 项目周期
                const periodCell = row.insertCell(2);
                periodCell.textContent = formatDateForDisplay(project.startDate) + ' - ' + formatDateForDisplay(project.endDate);
                
                // 阶段色块（每个阶段一列）
                phases.forEach((phase, index) => {
                    const phaseCell = row.insertCell(3 + index);
                    phaseCell.className = 'phase-cell';
                    
                    const phaseSegment = document.createElement('div');
                    phaseSegment.className = 'phase-segment';
                    phaseSegment.setAttribute('data-phase', phase);
                    phaseSegment.setAttribute('data-planned', project.phases[phase].planned ? formatDateForDisplay(project.phases[phase].planned) : '未设置');
                    phaseSegment.setAttribute('data-actual', project.phases[phase].actual ? formatDateForDisplay(project.phases[phase].actual) : '未完成');
                    
                    // 设置阶段状态
                    const status = getPhaseStatus(project.phases[phase].planned, project.phases[phase].actual);
                    phaseSegment.classList.add(status);
                    
                    phaseCell.appendChild(phaseSegment);
                });
                
                // 入库时间
                const storageCell = row.insertCell(14);
                storageCell.textContent = project.phases['入库时间'].actual ? formatDateForDisplay(project.phases['入库时间'].actual) : '未设置';
                
                // 操作按钮
                const actionCell = row.insertCell(15);
                actionCell.innerHTML = `
                    <button class="action-btn edit-btn">编辑</button>
                    <button class="action-btn delete-btn">删除</button>
                    <select class="status-select" data-project-id="${project.id}">
                        <option value="">选择状态</option>
                        <option value="research" ${project.status === 'research' ? 'selected' : ''}>在研</option>
                        <option value="completed" ${project.status === 'completed' ? 'selected' : ''}>已结项</option>
                        <option value="paused" ${project.status === 'paused' ? 'selected' : ''}>暂停</option>
                        <option value="terminated" ${project.status === 'terminated' ? 'selected' : ''}>终止</option>
                    </select>
                `;
                
                // 添加事件监听器
                actionCell.querySelector('.edit-btn').addEventListener('click', () => editProject(project.id));
                actionCell.querySelector('.delete-btn').addEventListener('click', () => deleteProject(project.id));
                actionCell.querySelector('.status-select').addEventListener('change', (e) => {
                    updateProjectStatus(project.id, e.target.value);
                });
            });
        }

        // 获取阶段状态
        function getPhaseStatus(plannedDate, actualDate) {
            if (!plannedDate) return 'future'; // 未设置计划日期，视为未开始
            
            const today = new Date();
            today.setHours(0, 0, 0, 0);
            const planned = new Date(plannedDate);
            planned.setHours(0, 0, 0, 0);
            
            if (actualDate) {
                // 有实际完成日期
                const actual = new Date(actualDate);
                actual.setHours(0, 0, 0, 0);
                
                if (actual <= planned) {
                    return 'completed'; // 按时完成
                } else {
                    return 'overdue-completed'; // 超期完成
                }
            } else {
                // 没有实际完成日期
                if (planned < today) {
                    return 'overdue'; // 超期未完成
                } else {
                    const daysUntilDue = Math.ceil((planned - today) / (1000 * 60 * 60 * 24));
                    if (daysUntilDue <= 3) {
                        return 'warning'; // 即将到期
                    } else {
                        return 'future'; // 未开始
                    }
                }
            }
        }

        // 格式化日期显示
        function formatDateForDisplay(dateString) {
            if (!dateString) return '未设置';
            const date = new Date(dateString);
            return `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`;
        }

        // 更新项目状态
        function updateProjectStatus(projectId, newStatus) {
            const project = projects.find(p => p.id === projectId);
            if (project) {
                if (newStatus === '') {
                    // 取消选择，恢复默认状态
                    project.status = 'research';
                } else {
                    project.status = newStatus;
                }
                renderProjectsTable();
                updateStats();
            }
        }

        // 更新统计信息
        function updateStats() {
            // 在研项目数量（排除已结项、暂停、终止的项目）
            const researchProjects = projects.filter(p => p.status === 'research').length;
            researchCountEl.textContent = researchProjects;
            
            // 评估中的项目数量 - 现在由用户手动输入，不再自动计算
            
            // 本月需结项项目数量 - 修正为包括所有本月计划结项的项目，排除暂停和终止状态
            const currentMonth = new Date().getMonth();
            const currentYear = new Date().getFullYear();
            const dueThisMonth = projects.filter(p => {
                const completionDate = new Date(p.phases['结项'].planned);
                return completionDate.getMonth() === currentMonth && 
                       completionDate.getFullYear() === currentYear &&
                       p.status !== 'paused' && p.status !== 'terminated';
            }).length;
            dueThisMonthCountEl.textContent = dueThisMonth;
            
            // 本月待结项项目数量 - 本月需结项但未结项的项目数量
            const pendingThisMonth = projects.filter(p => {
                const completionDate = new Date(p.phases['结项'].planned);
                return completionDate.getMonth() === currentMonth && 
                       completionDate.getFullYear() === currentYear &&
                       p.status !== 'completed'; // 未结项的项目
            }).length;
            pendingThisMonthCountEl.textContent = pendingThisMonth;
            
            // 更新品类统计
            updateCategoryStats();
        }

        // 更新品类统计 - 修改为将基础品类以外的项目归到小家电
        function updateCategoryStats() {
            categoryStatsEl.innerHTML = '';
            
            // 初始化计数对象
            const counts = {};
            displayCategories.forEach(cat => { counts[cat] = 0; });
            
            // 遍历项目进行统计
            projects.forEach(project => {
                if (baseCategories.includes(project.category)) {
                    // 如果是基础品类，直接计数
                    counts[project.category]++;
                } else {
                    // 其他所有品类都归到小家电
                    counts["小家电"]++;
                }
            });
            
            // 更新显示
            displayCategories.forEach(category => {
                const count = counts[category];
                
                const categoryItem = document.createElement('div');
                categoryItem.className = 'category-item';
                categoryItem.innerHTML = `
                    <div class="category-name">${category}</div>
                    <div class="category-count">${count}</div>
                `;
                
                categoryStatsEl.appendChild(categoryItem);
            });
        }

        // 填充品类筛选下拉框
        function populateCategoryFilter() {
            categoryFilter.innerHTML = '<option value="all">全部品类</option>';
            displayCategories.forEach(category => {
                const option = document.createElement('option');
                option.value = category;
                option.textContent = category;
                categoryFilter.appendChild(option);
            });
        }

        // 验证阶段日期是否在项目周期内
        function validatePhaseDates(startDate, endDate, phasesData) {
            const start = new Date(startDate);
            const end = new Date(endDate);
            
            // 检查所有阶段（除了入库时间）的计划日期是否在项目周期内
            for (const phase in phasesData) {
                if (phase !== "入库时间" && phasesData[phase].planned) {
                    const phaseDate = new Date(phasesData[phase].planned);
                    if (phaseDate < start || phaseDate > end) {
                        return false;
                    }
                }
            }
            return true;
        }

        // 添加新项目
        function addNewProject() {
            editingProjectId = null;
            modalTitle.textContent = '添加新项目';
            projectForm.reset();
            
            // 设置默认日期
            const today = new Date();
            const defaultDate = today.toISOString().split('T')[0];
            document.getElementById('startDate').value = defaultDate;
            
            const endDate = new Date(today);
            endDate.setMonth(today.getMonth() + 6); // 默认6个月后
            document.getElementById('endDate').value = endDate.toISOString().split('T')[0];
            
            // 设置阶段默认日期（递增）
            for (let i = 1; i <= 12; i++) {
                const plannedInput = document.getElementById(`phase${i}-planned`);
                const actualInput = document.getElementById(`phase${i}-actual`);
                if (plannedInput) {
                    const phaseDate = new Date(today);
                    phaseDate.setDate(today.getDate() + (i * 10)); // 每个阶段间隔10天
                    plannedInput.value = phaseDate.toISOString().split('T')[0];
                }
                if (actualInput) {
                    actualInput.value = ''; // 实际日期默认为空
                }
            }
            
            projectModal.style.display = 'flex';
        }

        // 编辑项目
        function editProject(projectId) {
            editingProjectId = projectId;
            const project = projects.find(p => p.id === projectId);
            
            if (project) {
                modalTitle.textContent = '编辑项目';
                document.getElementById('projectId').value = project.id;
                document.getElementById('productCategory').value = project.category;
                document.getElementById('productModel').value = project.model;
                document.getElementById('startDate').value = project.startDate;
                document.getElementById('endDate').value = project.endDate;
                
                // 设置阶段日期
                const allPhases = [...phases, "入库时间"];
                allPhases.forEach((phase, index) => {
                    const plannedInput = document.getElementById(`phase${index+1}-planned`);
                    const actualInput = document.getElementById(`phase${index+1}-actual`);
                    if (plannedInput && project.phases[phase]) {
                        plannedInput.value = project.phases[phase].planned || '';
                    }
                    if (actualInput && project.phases[phase]) {
                        actualInput.value = project.phases[phase].actual || '';
                    }
                });
                
                projectModal.style.display = 'flex';
            }
        }

        // 保存项目
        function saveProject(event) {
            event.preventDefault();
            
            // 收集阶段日期
            const phasesData = {};
            const allPhases = [...phases, "入库时间"];
            
            allPhases.forEach((phase, index) => {
                const plannedInput = document.getElementById(`phase${index+1}-planned`);
                const actualInput = document.getElementById(`phase${index+1}-actual`);
                phasesData[phase] = {
                    planned: plannedInput.value,
                    actual: actualInput.value
                };
            });
            
            const startDate = document.getElementById('startDate').value;
            const endDate = document.getElementById('endDate').value;
            
            // 验证阶段日期是否在项目周期内
            if (!validatePhaseDates(startDate, endDate, phasesData)) {
                alert('错误：所有阶段的计划完成日期必须在项目周期内（开始日期和结束日期之间）');
                return;
            }
            
            const projectData = {
                id: editingProjectId || Date.now(),
                category: document.getElementById('productCategory').value,
                model: document.getElementById('productModel').value,
                startDate: startDate,
                endDate: endDate,
                phases: phasesData,
                status: 'research' // 新项目默认为在研状态
            };
            
            if (editingProjectId) {
                // 更新现有项目
                const index = projects.findIndex(p => p.id === editingProjectId);
                if (index !== -1) {
                    projects[index] = projectData;
                }
            } else {
                // 添加新项目
                projects.push(projectData);
            }
            
            projectModal.style.display = 'none';
            renderProjectsTable();
            updateStats();
            populateCategoryFilter(); // 更新品类筛选选项
        }

        // 删除项目
        function deleteProject(projectId) {
            if (confirm('确定要删除这个项目吗？')) {
                projects = projects.filter(p => p.id !== projectId);
                renderProjectsTable();
                updateStats();
                populateCategoryFilter(); // 更新品类筛选选项
            }
        }

        // 导出Excel功能
        function exportToExcel() {
            try {
                // 准备Excel数据
                const excelData = [];
                
                // 添加表头
                const headers = [
                    '产品品类', '产品型号', '项目状态', '开始日期', '结束日期',
                    '方案评估计划', '方案评估实际', '需求确定计划', '需求确定实际',
                    '初样评审计划', '初样评审实际', '样机评审计划', '样机评审实际',
                    '立项计划', '立项实际', '外观样机计划', '外观样机实际',
                    '样机测试计划', '样机测试实际', '产品认证计划', '产品认证实际',
                    '试产准备计划', '试产准备实际', '试产计划', '试产实际',
                    '结项计划', '结项实际', '入库时间计划', '入库时间实际'
                ];
                excelData.push(headers);
                console.info(projects)
                // 添加项目数据
                projects.forEach(project => {
                    const row = [
                        project.category,
                        project.model,
                        getStatusText(project.status),
                        project.startDate,
                        project.endDate,
                        project.phases['方案评估'].planned || '',
                        project.phases['方案评估'].actual || '',
                        project.phases['需求确定'].planned || '',
                        project.phases['需求确定'].actual || '',
                        project.phases['初样评审'].planned || '',
                        project.phases['初样评审'].actual || '',
                        project.phases['样机评审'].planned || '',
                        project.phases['样机评审'].actual || '',
                        project.phases['立项'].planned || '',
                        project.phases['立项'].actual || '',
                        project.phases['外观样机'].planned || '',
                        project.phases['外观样机'].actual || '',
                        project.phases['样机测试'].planned || '',
                        project.phases['样机测试'].actual || '',
                        project.phases['产品认证'].planned || '',
                        project.phases['产品认证'].actual || '',
                        project.phases['试产准备'].planned || '',
                        project.phases['试产准备'].actual || '',
                        project.phases['试产'].planned || '',
                        project.phases['试产'].actual || '',
                        project.phases['结项'].planned || '',
                        project.phases['结项'].actual || '',
                        project.phases['入库时间'].planned || '',
                        project.phases['入库时间'].actual || ''
                    ];
                    excelData.push(row);
                });
                
                // 创建工作簿
                const wb = XLSX.utils.book_new();
                const ws = XLSX.utils.aoa_to_sheet(excelData);
                
                // 设置列宽
                const colWidths = [
                    { wch: 10 }, { wch: 15 }, { wch: 10 }, { wch: 12 }, { wch: 12 },
                    { wch: 12 }, { wch: 12 }, { wch: 12 }, { wch: 12 },
                    { wch: 12 }, { wch: 12 }, { wch: 12 }, { wch: 12 },
                    { wch: 12 }, { wch: 12 }, { wch: 12 }, { wch: 12 },
                    { wch: 12 }, { wch: 12 }, { wch: 12 }, { wch: 12 },
                    { wch: 12 }, { wch: 12 }, { wch: 12 }, { wch: 12 },
                    { wch: 12 }, { wch: 12 }, { wch: 12 }, { wch: 12 }
                ];
                ws['!cols'] = colWidths;
                
                // 将工作表添加到工作簿
                XLSX.utils.book_append_sheet(wb, ws, '项目进度数据');
                
                // 生成Excel文件并下载
                const currentDate = new Date().toISOString().split('T')[0];
                XLSX.writeFile(wb, `项目进度管理数据_${currentDate}.xlsx`);
                
            } catch (error) {
                console.error('导出Excel时出错:', error);
                alert('导出Excel文件时出现错误，请检查浏览器控制台获取详细信息。');
            }
        }

        // 获取状态文本
        function getStatusText(status) {
            const statusMap = {
                'research': '在研',
                'completed': '已结项',
                'paused': '暂停',
                'terminated': '终止'
            };
            return statusMap[status] || status;
        }

        // 导入Excel功能
        function importFromExcel(file) {
            const reader = new FileReader();
            
            reader.onload = function(e) {
                try {
                    const data = new Uint8Array(e.target.result);
                    const workbook = XLSX.read(data, { type: 'array' });
                    
                    // 获取第一个工作表
                    const worksheet = workbook.Sheets[workbook.SheetNames[0]];
                    const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 });
                    
                    if (jsonData.length < 2) {
                        alert('Excel文件中没有数据或格式不正确');
                        return;
                    }
                    
                    // 获取表头
                    const headers = jsonData[0];
                    
                    // 验证表头格式
                    const expectedHeaders = [
                        '产品品类', '产品型号', '项目状态', '开始日期', '结束日期',
                        '方案评估计划', '方案评估实际', '需求确定计划', '需求确定实际',
                        '初样评审计划', '初样评审实际', '样机评审计划', '样机评审实际',
                        '立项计划', '立项实际', '外观样机计划', '外观样机实际',
                        '样机测试计划', '样机测试实际', '产品认证计划', '产品认证实际',
                        '试产准备计划', '试产准备实际', '试产计划', '试产实际',
                        '结项计划', '结项实际', '入库时间计划', '入库时间实际'
                    ];
                    
                    let validFormat = true;
                    expectedHeaders.forEach((header, index) => {
                        if (headers[index] !== header) {
                            validFormat = false;
                        }
                    });
                    
                    if (!validFormat) {
                        alert('Excel文件格式不正确，请使用导出的模板文件');
                        return;
                    }
                    
                    let importedCount = 0;
                    let updatedCount = 0;
                    let skippedCount = 0;
                    
                    // 处理数据行（从第二行开始）
                    for (let i = 1; i < jsonData.length; i++) {
                        const row = jsonData[i];
                        
                        // 跳过空行
                        if (!row || row.length === 0 || !row[0]) {
                            skippedCount++;
                            continue;
                        }
                        
                        // 验证必要字段
                        if (!row[0] || !row[1] || !row[3] || !row[4]) {
                            skippedCount++;
                            continue;
                        }
                        
                        // 创建项目数据对象
                        const projectData = {
                            id: Date.now() + i, // 生成新ID
                            category: row[0],
                            model: row[1],
                            startDate: formatExcelDate(row[3]),
                            endDate: formatExcelDate(row[4]),
                            phases: {
                                "方案评估": { planned: formatExcelDate(row[5]), actual: formatExcelDate(row[6]) },
                                "需求确定": { planned: formatExcelDate(row[7]), actual: formatExcelDate(row[8]) },
                                "初样评审": { planned: formatExcelDate(row[9]), actual: formatExcelDate(row[10]) },
                                "样机评审": { planned: formatExcelDate(row[11]), actual: formatExcelDate(row[12]) },
                                "立项": { planned: formatExcelDate(row[13]), actual: formatExcelDate(row[14]) },
                                "外观样机": { planned: formatExcelDate(row[15]), actual: formatExcelDate(row[16]) },
                                "样机测试": { planned: formatExcelDate(row[17]), actual: formatExcelDate(row[18]) },
                                "产品认证": { planned: formatExcelDate(row[19]), actual: formatExcelDate(row[20]) },
                                "试产准备": { planned: formatExcelDate(row[21]), actual: formatExcelDate(row[22]) },
                                "试产": { planned: formatExcelDate(row[23]), actual: formatExcelDate(row[24]) },
                                "结项": { planned: formatExcelDate(row[25]), actual: formatExcelDate(row[26]) },
                                "入库时间": { planned: formatExcelDate(row[27]), actual: formatExcelDate(row[28]) }
                            },
                            status: getStatusFromText(row[2]) || 'research'
                        };
                        
                        // 查找是否已存在相同型号和品类的项目 - 修正为使用型号和品类共同匹配
                        const existingIndex = projects.findIndex(p => p.model === projectData.model && p.category === projectData.category);
                        
                        if (existingIndex !== -1) {
                            // 更新现有项目
                            projects[existingIndex] = projectData;
                            updatedCount++;
                        } else {
                            // 添加新项目
                            projects.push(projectData);
                            importedCount++;
                        }
                    }
                    
                    // 显示导入结果
                    alert(`导入完成！\n新增项目: ${importedCount} 个\n更新项目: ${updatedCount} 个\n跳过项目: ${skippedCount} 个`);
                    
                    // 刷新界面
                    renderProjectsTable();
                    updateStats();
                    populateCategoryFilter(); // 更新品类筛选选项
                    
                } catch (error) {
                    console.error('导入Excel时出错:', error);
                    alert('导入Excel文件时出现错误，请检查文件格式是否正确');
                }
            };
            
            reader.readAsArrayBuffer(file);
        }

        // 格式化Excel日期
        function formatExcelDate(excelDate) {
            if (!excelDate) return '';
            
            // 如果是字符串格式的日期
            if (typeof excelDate === 'string') {
                // 尝试解析各种日期格式
                const date = new Date(excelDate);
                if (!isNaN(date.getTime())) {
                    return date.toISOString().split('T')[0];
                }
                return excelDate; // 返回原始字符串
            }
            
            // 如果是Excel序列号日期
            if (typeof excelDate === 'number') {
                const date = new Date((excelDate - 25569) * 86400 * 1000);
                return date.toISOString().split('T')[0];
            }
            
            return '';
        }

        // 从状态文本获取状态值
        function getStatusFromText(statusText) {
            if (!statusText) return 'research';
            
            const statusMap = {
                '在研': 'research',
                '已结项': 'completed',
                '暂停': 'paused',
                '终止': 'terminated'
            };
            
            return statusMap[statusText] || 'research';
        }

        // 设置事件监听器
        function setupEventListeners() {
            addProjectBtn.addEventListener('click', addNewProject);
            exportExcelBtn.addEventListener('click', exportToExcel);
            cancelBtn.addEventListener('click', () => {
                projectModal.style.display = 'none';
            });
            projectForm.addEventListener('submit', saveProject);
            
            // 导入功能 - 直接监听文件输入变化
            excelFile.addEventListener('change', (e) => {
                if (e.target.files.length > 0) {
                    importFromExcel(e.target.files[0]);
                    // 清空文件输入，允许重复选择同一文件
                    e.target.value = '';
                }
            });
            
            // 过滤按钮事件
            filterBtns.forEach(btn => {
                btn.addEventListener('click', () => {
                    filterBtns.forEach(b => b.classList.remove('active'));
                    btn.classList.add('active');
                    currentFilter = btn.getAttribute('data-filter');
                    renderProjectsTable();
                });
            });
            
            // 品类筛选事件
            categoryFilter.addEventListener('change', (e) => {
                currentCategory = e.target.value;
                renderProjectsTable();
            });
            
            // 搜索功能
            searchInput.addEventListener('input', (e) => {
                searchTerm = e.target.value;
                renderProjectsTable();
            });
            
            // 评估项目数量输入框事件
            evaluationCountInput.addEventListener('change', (e) => {
                // 保存到本地存储
                localStorage.setItem('evaluationCount', e.target.value);
            });
            
            // 点击模态框外部关闭
            window.addEventListener('click', (event) => {
                if (event.target === projectModal) {
                    projectModal.style.display = 'none';
                }
            });
        }

        // 初始化看板
        document.addEventListener('DOMContentLoaded', initKanban);
	
		
    </script>
</body>
</html>
